package com.xca.rxjavademo.views;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.xca.rxjavademo.R;
import com.xca.rxjavademo.utils.TimeUtils;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private Observable<Integer> observable ;
    private Observer<Integer> observer;

    private TextView tv1 , tv2 , tv3;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv1 = findViewById(R.id.toDayImg);
        tv2 = findViewById(R.id.toWeather);
        tv3 = findViewById(R.id.toNews);

        tv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this , DayImageActivity.class);
                 startActivity(intent);
            }
        });

        tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this , WeatherActivity.class);
                startActivity(intent);
            }
        });

        tv3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this , NewsActivity.class);
                startActivity(intent);
            }
        });

//        createObservable();
//        createObserver();
//        observable.subscribe(observer);
    }

    private void createObservable(){
         observable = Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<Integer> emitter) throws Throwable {
                emitter.onNext(1);
                emitter.onNext(2);
                emitter.onNext(3);
                emitter.onComplete();//完成
            }
        });
    }

    private void createObserver(){
       observer = new Observer<Integer>() {
           @Override
           public void onSubscribe(@NonNull Disposable d) {
               Log.d(TAG, "开始采用subscribe连接");
           }

           @Override
           public void onNext(@NonNull Integer integer) {
               Log.d(TAG, "对Next事件" + integer + "作出响应");
           }

           @Override
           public void onError(@NonNull Throwable e) {
               Log.d(TAG, "对Error事件作出响应");
           }

           @Override
           public void onComplete() {
               Log.d(TAG, "对Complete事件作出响应");
           }
       };
    }
}